package com.sc.nft.admin.controller;


import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.annotation.UserLogin;
import com.sc.nft.entity.dto.SearchEditDTO;
import com.sc.nft.entity.dto.SearchExistListDTO;
import com.sc.nft.entity.dto.SearchSaveDTO;
import com.sc.nft.entity.dto.SearchStartAndStopDTO;
import com.sc.nft.entity.vo.SearchExistListVO;
import com.sc.nft.entity.vo.SearchListVO;
import com.sc.nft.service.SearchService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 搜索配置(Search)表控制层
 *
 * @author 王伟成
 * @since 2024-03-05 15:50:40
 */

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/search")
@Api(tags = "搜索")
public class SearchController {
    /**
     * 服务对象
     */
    private final SearchService searchService;


    @ApiOperation(value = "所有可用集合列表", notes = "所有可用集合列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/existList", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<SearchExistListVO> existList(@RequestBody SearchExistListDTO searchExistListDTO)  {
        return PageResult.success(searchService.existList(searchExistListDTO));
    }

    @ApiOperation(value = "搜索集合列表", notes = "搜索集合列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/displayList", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<List<SearchListVO>> displayList()  {
        return Result.success(searchService.displayList());
    }


    @ApiOperation(value = "新增一个新的搜索选项", notes = "新增一个新的搜索选项", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/save", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result save(@Valid @RequestBody SearchSaveDTO searchSaveDTO)  {
        searchService.save(searchSaveDTO);
        return Result.success();
    }

    @ApiOperation(value = "修改一个搜搜选项", notes = "修改一个搜搜选项", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/edit", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result edit(@Valid @RequestBody SearchEditDTO searchEditDTO)  {
        searchService.edit(searchEditDTO);
        return Result.success();
    }

    @ApiOperation(value = "启动或停用一个搜索选项", notes = "启动或停用一个搜索选项", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/startAndStop", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result startAndStop(@Valid @RequestBody SearchStartAndStopDTO searchStartAndStopDTO)  {
        searchService.startAndStop(searchStartAndStopDTO);
        return Result.success();
    }

}
